<%--
  Created by IntelliJ IDEA.
  User: houxy
  Date: 2016/8/4
  Time: 11:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<c:set var="isShowAll" value="${sessionScope.isShowAll}"/>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>救助飞行运行管理系统</title>

    <link rel="stylesheet" type="text/css"
          href='<spring:url value="/resources/common/bootstrap/css/bootstrap.min.css"></spring:url>'>

    <link rel="stylesheet" type="text/css"
          href='<spring:url value="/resources/common/metronic/media/css/style-metro.css"></spring:url>'>

    <link rel="stylesheet" type="text/css"
          href='<spring:url value="/resources/common/metronic/media/css/style.css"></spring:url>'>

    <link rel="stylesheet" type="text/css"
          href='<spring:url value="/resources/common/metronic/media/css/font-awesome.min.css"></spring:url>'>

    <script src='<spring:url value="/resources/js/jquery-1.11.0.js"></spring:url>'></script>

    <script src='<spring:url value="/resources/common/metronic/media/js/bootstrap.min.js"></spring:url>'></script>

    <script src='<spring:url value="/resources/common/metronic/media/js/bootstrap-modal.js"></spring:url>'></script>

    <script src='<spring:url value="/resources/common/metronic/media/js/bootstrap-modalmanager.js"></spring:url>'></script>

    <script src='<spring:url value="/resources/userJs/ajaxError.js"/>'></script>

    <script src='<spring:url value="/resources/userJs/overrideAlertAndConfirm.js"/>'></script>

    <script src='<spring:url value="/resources/js/crypto-js.min.js"/>'></script>

    <script src='<spring:url value="/resources/js/cryptoUtil.js"/>'></script>

    <link rel="shortcut icon" href='<spring:url value="/resources/images/logo.ico"></spring:url>'/>
    <script>
        /**
         * 检查token格式是否正确
         * @param url
         */
        function checkToken(url) {
            $("#passForm").attr("action", url);
            $("#passForm").submit();
        }

        let ctx = "${ctx}";

        function resetPassword() {
            let oldPassword = $("#oldPassword").val().trim();
            let newPassword = $("#newPassword").val().trim();
            let confPassword = $("#confPassword").val().trim();
            let key = genAesSecret()
            if (oldPassword == '') {
                alert("请输入旧密码！")
                return;
            }
            if (newPassword == '') {
                alert("请输入新密码！")
                return;
            }
            if(oldPassword == newPassword){
                alert("旧密码和新密码不能相同！")
            }
            if(!regex.test(newPassword)){
                alert("密码强度不符合要求（须包含大小写字母、数字及特殊字符，且长度8位以上）！")
                return;
            }
            if (confPassword == '') {
                alert("请输入确认密码！")
                return;
            }
            if (newPassword != confPassword) {
                alert("两次输入新密码不一致！");
                return;
            }
            oldPassword = encrypt(oldPassword,key)
            newPassword = encrypt(newPassword,key)
            confPassword = encrypt(confPassword,key)
            $.ajax({
                url: ctx + "/resetPassword",
                type: "post",
                dataType: "json",
                data: {"oldPassword": oldPassword, "newPassword": newPassword, "confPassword": confPassword,"key":key},
                async: false,
                cache: "false",
                success: function (data) {
                    let status = data.status
                    if (status == 0) {
                        alert("修改成功！", ctx + "/logout");
                    } else {
                        alert(getMessage(data["msg"]));
                    }
                },
                error: function () {
                    alert("系统繁忙，请稍后重试！");
                }
            })
        }

        function cancelModify() {
            $("#oldPassword").val("");
            $("#newPassword").val("");
            $("#confPassword").val("");
        }

        $(document).ready(function () {
            let message = '${errorMessage}';
            if (message != null && message != '') {
                let url = delQueStr(window.location.href, 'message');
                alert(message, url);
            }else{
                let passwordState = '${passwordState}'
                if(passwordState == 11) {
                    let days = '${days}'
                  alert("密码"+days+"天后到期，请尽快修改！");
                }
            }
        })

        //清除url参数
        function delQueStr(url, ref) {
            let str = "";
            if (url.indexOf('?') != -1) {
                str = url.substr(url.indexOf('?') + 1);
            } else {
                return url;
            }
            let arr = "";
            let returnurl = "";
            let setparam = "";
            if (str.indexOf('&') != -1) {
                arr = str.split('&');
                for (i in arr) {
                    if (arr[i].split('=')[0] != ref) {
                        returnurl = returnurl + arr[i].split('=')[0] + "=" + arr[i].split('=')[1] + "&";
                    }
                }
                return url.substr(0, url.indexOf('?')) + "?" + returnurl.substr(0, returnurl.length - 1);
            } else {
                arr = str.split('=');
                if (arr[0] == ref) {
                    return url.substr(0, url.indexOf('?'));
                } else {
                    return url;
                }
            }
        }
        //页面加载完成获取消息信息
        $(function () {
            $.ajax({
                url: ctx + "/systemMessageManager/getPersonMessageCount",
                type: "post",
                dataType: "json",
                data: {},
                async: false,
                cache: "false",
                success: function (data) {
                    let status = data.status
                    if (status == 0) {
                        let count = parseInt(data["count"]);
                        if (count == 0) {
                            $("#message").hide();
                        } else if (0 < count && count < 100) {
                            $("#message").show();
                            $("#message").html(count)
                        } else if (count > 99) {
                            $("#message").show();
                            $("#message").html('99+')
                        } else {
                            $("#message").hide();
                        }
                    } else {
                        alert("消息信息获取失败！");
                    }
                },
                error: function () {
                    alert("系统繁忙，请稍后重试！");
                }
            })
        });
    </script>
    <style>
        body {
            margin: 0px;
            background-image: url('<spring:url value="/resources/images/back-g.png"></spring:url>');
            background-repeat: no-repeat;
            filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";
            -moz-background-size: 100% 100%;
            background-size: cover;
            height: 100%;
        }

        .modal label {
            font-size: 14px;
            font-weight: normal;
        }

        .row label {
            color: #000;
        }

        .dropdown a {
            padding: 0;
        }

        #header {
            background-color: #3498db;
            width: 100%;
            height: 70px;
        }

        #logo {
            width: 75px;
        }

        #sys {
            color: #fff;
            font-size: 25px;
            line-height: 65px;
        }

        .rel {
            margin-right: 20px;
        }

        #head-right {
            margin-right: 10px;
            color: #fff;
            font-size: 14px;
        }

        .con {
            text-align: center;
            height: 200px;
        }

        .row {
            margin-top: 8%;
        }

        .col-md-3 label {
            width: 100%;
            height: 50px;
            line-height: 50px;
            text-align: center;
            font-size: 20px;
            background-color: #fff;
            color: #696969;
        }

        #footer {
            margin-top: 80px;
            width: 100%;
            text-align: center;
            color: #ccc;
        }

        .nav > li > a:hover {
            text-decoration: none !important;
            background-color: #999 !important;
        }

        .open > a {
            text-decoration: none;
            background-color: #999 !important;
        }

        .validTip {
            font-size: 20px;
            color: red;
            font-weight: bold;
            padding-top: 5px;
        }

        .rel {
            font-size: 16px;
            margin-right: 24px;
            margin-top: 23px;
        }

        .alert_button {
            margin-right: 0px;
            width: 56px;
            border: 0;
            padding: 7px 14px;
            outline: none;
            line-height: 20px;
            margin-bottom: 0;
            display: inline-block;
            vertical-align: middle;
            height: 30px;
            color: white;
            text-shadow: none;
            background-color: #35aa47;
        }

        .alert_button:hover, .alert_button:focus {
            border: 0;
            background-color: #1d943b;
            color: #fff;
            outline: none;
        }
    </style>
</head>
<body>
<div id="header">
    <div id="head-right">
        <ul class="nav pull-right" style="margin-right:91px;margin-top:23px;font-size:16px;">
            <li class="dropdown user">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" style="padding:0">
                    <span class="username" style="color:#fff"><%=session.getAttribute("authUserName") %></span>
                    <i class="icon-angle-down"></i>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="#reset_password" data-toggle="modal"><i class="icon-unlock"></i>修改密码</a></li>
                    <%--<li class="divider"></li>--%>
                    <%--<c:if test="${isShowAll=='1' || isShowAll=='0'|| isShowAll=='2'}">--%>
                    <%--<li><a href="toTreeNode"><i class="icon-globe"></i>组织维护</a></li>--%>
                    <%--<li class="divider"></li>--%>
                    <%--<li><a href="toUserMaintain"><i class="icon-group"></i>用户维护 </a></li>--%>
                    <%--<li class="divider"></li>--%>
                    <%--</c:if>--%>
                    <li><a href='<spring:url value="/logout"/> '><i class="icon-key"></i> 退出登录</a></li>
                </ul>
            </li>
        </ul>
        <%--<span class="pull-right rel" ><span class="icon-envelope-alt"></span></span>--%>
        <span class="pull-right rel">
            <span class="icon-envelope-alt" style=""> </span>&nbsp; &nbsp;&nbsp;
                <i id="message"
                   style="font-style:normal;position: absolute;  right: auto; display: inline-block;font-size:14px;  line-height: 14px; color: #fff; background-color: #f10215; border-radius: 9px;   min-width:18px; text-align: center;padding: 2px;margin-top:-7px;margin-left: -34px;display: none"></i>
            <span class="icon-group"></span> 所属部门：${sessionScope.loginUserDeptName}</span>
    </div>
</div>

<div class="container">
    <div class="row form-inline">
        <c:forEach items="${urlInfo}" var="u">
            <c:if test="${u.name=='飞行航务系统'}">
                <div class="col-md-3">
                    <a href="javascript:" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#28b779">
                            <img class="long" src='<spring:url value="/resources/images/b-1.png"></spring:url>'>
                        </div>
                        <label>飞行航务系统</label>
                    </a>
                </div>
            </c:if>
            <c:if test="${u.name=='飞机情报系统'}">
                <div class="col-md-3">
                    <a href="javascript:" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#ffb849">
                            <img class="long" src='<spring:url value="/resources/images/b-2.png"></spring:url>'>
                        </div>
                        <label>飞行情报系统</label>
                    </a>
                </div>
            </c:if>
            <c:if test="${u.name=='安全管理系统'}">
                <div class="col-md-3">
                    <a href="javascript:" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#c6eb2b">
                            <img class="long" src='<spring:url value="/resources/images/b-6.png"></spring:url>'>
                        </div>
                        <label>安全管理系统</label>
                    </a>
                </div>
            </c:if>
            <c:if test="${u.name=='培训考试系统'}">
                <div class="col-md-3">
                    <a href="javascript:" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#1ca94d">
                            <img class="long" src='<spring:url value="/resources/images/b-7.png"></spring:url>'>
                        </div>
                        <label>培训考试系统</label>
                    </a>
                </div>
            </c:if>
        </c:forEach>
    </div>
    <div class="row">
        <c:forEach items="${urlInfo}" var="u">
            <c:if test="${u.name=='机务维修系统'}">
                <div class="col-md-3">
                    <a href="javascript:" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#862a99">
                            <img class="long" src='<spring:url value="/resources/images/b-5.png"></spring:url>'>
                        </div>
                        <label>机务维修系统</label>
                    </a>
                </div>
            </c:if>
            <c:if test="${u.name=='综合查询系统'}">
                <div class="col-md-3">
                    <a href="javascript:" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#26abe2">
                            <img class="long" src='<spring:url value="/resources/images/b-3.png"></spring:url>'>
                                <%--<i id="message"style="font-style:normal;position: absolute;  top:-16px;  left: 259px; right: auto; display: inline-block;font-size: 25px;  line-height: 32px; color: #fff; background-color: #f10215; border-radius: 20px;   min-width: 36px; text-align: center;padding: 2px;display: none;" ></i>--%>
                        </div>
                        <label>综合查询系统</label>
                    </a>
                </div>
            </c:if>
            <c:if test="${u.name=='用户管理系统'}">
                <div class="col-md-3">
                    <a href="javascript:" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#8ec253">
                            <img class="long" src='<spring:url value="/resources/images/b-4.png"></spring:url>'>
                        </div>
                        <label>用户管理系统</label>
                    </a>
                </div>
            </c:if>
            <c:if test="${u.name=='待扩展'}">
                <div class="col-md-3">
                    <a href="javascript:void(0)" onclick="checkToken('${u.url}')">
                        <div class="con" style="background-color:#00c1ca">
                            <img class="long" src='<spring:url value="/resources/images/b-8.png"></spring:url>'>
                        </div>
                        <label>待扩展...</label>
                    </a>
                </div>
            </c:if>
        </c:forEach>
    </div>
</div>
<form action="" method="post" id="passForm">
    <input name="token" type="hidden" value="${token}"/>
</form>
<div id="footer">
    <span>Copyright © 2016 救助飞行运行管理系统</span>
</div>
<%--修改密码模态框--%>
<div id="reset_password" class="modal hide fade " tabindex="-1" data-width="760">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="cancel();"></button>
        <span id="add">
          <h4>修改密码</h4>
        </span>
    </div>
    <div class="modal-body">
        <form:form id="addForm">
            <input type="hidden" id="id" name="id">

            <div class="form-inline bom">
                <label class="help-inline span1" style="width:150px;text-align: right">旧密码：</label>
                <input type="password" id="oldPassword" name="oldPassword" class="input-data-middle"><span
                    class="validTip">*</span>
            </div>
            <div class="form-inline bom">
                <label class="help-inline span1" style="width:150px;text-align: right">新密码：</label>
                <input type="password" id="newPassword" name="newPassword" class="input-data-middle"><span
                    class="validTip">*</span>
            </div>
            <div class="form-inline bom">
                <label class="help-inline span1" style="width:150px;text-align: right">确认密码：</label>
                <input type="password" id="confPassword" name="confPassword" class="input-data-middle"><span
                    class="validTip">*</span>
            </div>
        </form:form>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn blue" onclick="resetPassword()">修改</button>
        <button type="button" data-dismiss="modal" class="btn" onclick="cancelModify()">取消</button>
    </div>
</div>
</body>
</html>
